# -*- coding: utf-8 -*-
import os,sys
from pyh2 import *
from dictdata import getdata

class PutHTML(object):
	"""docstring for PutHTML"""
	def __init__(self,dict={}):
		self.dict = getdata().DICTIONARY

	def pyhport(self):

		page = PyH('接口测试报告')#第一步：需要先生成含标题的HTML模板
		# <meta charset="utf-8">
		page << meta(charset='utf-8')
		page.addCSS('css/bootstrap.min.css')#第二步：需要加载我们要使用的Bootstrap模板css文件，需要的话还可以加载js
		page.addJS('js/jquery-3.3.1.min.js', 'js/bootstrap.min.js','js/myScript.js')
		Container = page << body(id='Body', cl='bg-warning') << div(id="container",cl="container") #第三步：通过移位符“<<”，来生成所属标签；“<<”左侧最终必须是page

		# 报告标题 start
		Headrow = Container << div(id="Headrow", cl="row")
		Headrow << h1(id="HeadH1",align="center") << p("Layout Test  ",id="HeadTxt") #+ span("chrome63", id="author")
		Headrow << br()
		# 报告标题 end

		# 数据统计 start
		Totalrow = Container << div(id="Totalrow", cl="Totalrow") << div(cl="jumbotron")
		# --测试使用时间，测试用例总数--
		test_time_txt = ["测试版本：", self.dict['Version']]
		# test_time_txt = [self.dict['Name'],self.dict['Name']]
		case_num = ["用例总数：", self.dict['All']]
		UTimerow = Totalrow << div(id="UTimerow", cl="row")
		UTimerow << div(cl="col-xs-12 col-md-6") << p(role="presentation") << span(test_time_txt[0]) << span(test_time_txt[1], cl="label label-default")
		UTimerow << div(cl="col-xs-12 col-md-6") << p(role="presentation") << span(case_num[0]) << span(case_num[1],cl="label label-primary")
		# --用例失败成功统计--
		Num1_txt = ["稳定失败：", self.dict['stablefail']]
		Num2_txt = ["浮动失败：", self.dict['floatfail']]
		Num3_txt = ["新增失败：", self.dict['Add']]
		Num4_txt = ["紧急失败：", self.dict['Crash']]
		Amountrow = Totalrow << div(id="Amountrow", cl="row")
		Num1 = Amountrow << div(id="Num1", type="button",cl="col-xs-12 col-md-3 btn btn-primary") << p(role="presentation") << span(Num1_txt[0]) << span(Num1_txt[1], cl="label label-danger")
		Num2 = Amountrow << div(id="Num2", type="button",cl="col-xs-12 col-md-3 btn btn-primary") << p(role="presentation") << span(Num2_txt[0]) << span(Num2_txt[1], cl="label label-success")
		Num3 = Amountrow << div(id="Num3", type="button",cl="col-xs-12 col-md-3 btn btn-primary") << p(role="presentation") << span(Num3_txt[0]) << span(Num3_txt[1], cl="label label-warning")
		Num4 = Amountrow << div(id="Num4", type="button",cl="col-xs-12 col-md-3 btn btn-primary") << p(role="presentation") << span(Num4_txt[0]) << span(Num4_txt[1], cl="label label-danger")
		# 数据统计 end 		

		#类型
		Type1_txt = ["Crash ", self.dict['Crash']]
		Type2_txt = ["Timeout ",self.dict['Timeout']]
		Type3_txt = ["Test failure ",self.dict['Text_Failure']]
		Type4_txt = ["Image failure ",self.dict['Image_Filure']]
		Type5_txt = ["Image+Test failure ",self.dict['Image_Test_Fiure']]
		Type6_txt = ["Skipeed ",self.dict['Skipeed']]
		Type7_txt = ["Missing ",self.dict['Missing']]
		Genre = Amountrow << div(id="Genre",cl="btn-group")
		Type1_txt = Genre << div(id="Type1", type="button",cl="btn btn-info") << span(Type1_txt[0]) << span(Type1_txt[1], cl="label label-danger")
		Type2_txt = Genre << div(id="Type2", type="button",cl="btn btn-info") << span(Type2_txt[0]) << span(Type2_txt[1], cl="label label-danger")
		Type3_txt = Genre << div(id="Type3", type="button",cl="btn btn-info") << span(Type3_txt[0]) << span(Type3_txt[1], cl="label label-danger")
		Type4_txt = Genre << div(id="Type4", type="button",cl="btn btn-info") << span(Type4_txt[0]) << span(Type4_txt[1], cl="label label-danger")
		Type5_txt = Genre << div(id="Type5", type="button",cl="btn btn-info") << span(Type5_txt[0]) << span(Type5_txt[1], cl="label label-danger")
		Type6_txt = Genre << div(id="Type6", type="button",cl="btn btn-info") << span(Type6_txt[0]) << span(Type6_txt[1], cl="label label-danger")
		Type7_txt = Genre << div(id="Type7", type="button",cl="btn btn-info") << span(Type7_txt[0]) << span(Type7_txt[1], cl="label label-danger")
		
		#类型end
		plans_title = "稳定失败用例"
		thead1 = ["用例编号","用例名称", "文件路径", "失败类型", "执行结果"]


		# 测试计划 start
		fd = self.dict['floatdata']
		counts = len(fd)
		floatfail = Container << div(id="floatfail", cl="row")
		float_title = "浮动失败用例"
		PlansTitle = floatfail << div(id="plans-title", cl="panel panel-primary") << div(cl="panel-heading") << span(float_title, cl="text-uppercase")
		Plan = floatfail << div(id="Plan", cl="col-xs-12 col-md-12") << table(cl="table table-striped")
		Plan << p()
		Thead1 = Plan 
		Thead1 << tr() << th(thead1[0]) + th(thead1[1]) + th(thead1[2]) + th(thead1[3]) + th(thead1[4])
		for x in range(counts):
			tbody1 = ['float_'+str(x+1),fd[x].split('/')[-1], fd[x], "Float", "Details"]
			Tbody1 = Plan #<< tbody()
			Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(p(tbody1[3], cl="label label-danger")) + td(a(tbody1[4], href="/layout-test-results/fast/canvas/OffscreenCanvas-2d-drawImage.html"))
		# end

		# 新增失败用例 start
		ad = self.dict['Add_data']
		# counts_sd = len(ad)
		Add = Container << div(id="Add", cl="row")
		# --栏目标题--
		add_title = "新增失败用例"
		PlansTitle = Add << div(id="plans-title", cl="panel panel-primary") << div(cl="panel-heading") << span(add_title, cl="text-uppercase")
		Plan = Add << div(id="Plan", cl="col-xs-12 col-md-12") << table(cl="table table-striped")
		Plan << p()
		Thead1 = Plan #<< thead()
		Thead1 << tr() << th(thead1[0]) + th(thead1[1]) + th(thead1[2]) + th(thead1[3]) + th(thead1[4])

		# # for x in range(counts_sd):
		# tbody1 = ['add_'+str(x+1),ad[x][0:10], ad[x], ad[x][-5], "Details"]
		# Tbody1 = Plan #<< tbody()
		# Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(p(tbody1[3], cl="label label-danger")) + td(a(tbody1[4], href="/layout-test-results/fast/canvas/OffscreenCanvas-2d-drawImage.html"))
		# --一个测试计划-- end
		# 测试计划 end

		# 测试计划 start
		cfd = self.dict['Crashdata']
		counts = len(cfd)
		Crashfail = Container << div(id="Crashfail", cl="row")
		crash_title = "紧急失败用例"
		PlansTitle = Crashfail << div(id="plans-title", cl="panel panel-primary") << div(cl="panel-heading") << span(crash_title, cl="text-uppercase")
		Plan = Crashfail << div(id="Plan", cl="col-xs-12 col-md-12") << table(cl="table table-striped")
		Plan << p()
		Thead1 = Plan 
		Thead1 << tr() << th(thead1[0]) + th(thead1[1]) + th(thead1[2]) + th(thead1[3]) + th(thead1[4])
		for x in range(counts):
			tbody1 = ['crashfail_'+str(x+1),cfd[x].split('/')[-1], cfd[x], "Crash", "Details"]
			Tbody1 = Plan #<< tbody()
			Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(p(tbody1[3], cl="label label-danger")) + td(a(tbody1[4], href="/layout-test-results/fast/canvas/OffscreenCanvas-2d-drawImage.html"))
		# end

		# 测试计划 start
		cd = self.dict['Crashdata']
		counts_cd = len(cd)
		Crash = Container << div(id="Crash", cl="row")
		PlansTitle = Crash << div(id="plans-title", cl="panel panel-primary") << div(cl="panel-heading") << span(plans_title, cl="text-uppercase")
		Plan = Crash << div(id="Plan", cl="col-xs-12 col-md-12") << table(cl="table table-striped")
		Plan << p()
		Thead1 = Plan
		Thead1 << tr() << th(thead1[0]) + th(thead1[1]) + th(thead1[2]) + th(thead1[3])+ th(thead1[3])
		for x in range(counts_cd):
			tbody1 = ['crash_'+str(x+1),cd[x].split('/')[-1], cd[x], 'Crash', "Details"]
			Tbody1 = Plan #<< tbody()
			Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(p(tbody1[3], cl="label label-danger")) + td(a(tbody1[4], href="/layout-test-results/fast/canvas/OffscreenCanvas-2d-drawImage.html"))

		# 测试计划 start
		tod = self.dict['Timeoutdata']
		counts = len(tod)
		Timeout = Container << div(id="Timeout", cl="row")
		PlansTitle = Timeout << div(id="plans-title", cl="panel panel-primary") << div(cl="panel-heading") << span(plans_title, cl="text-uppercase")
		Plan = Timeout << div(id="Plan", cl="col-xs-12 col-md-12") << table(cl="table table-striped")
		Plan << p()
		Thead1 = Plan #<< thead()
		Thead1 << tr() << th(thead1[0]) + th(thead1[1]) + th(thead1[2]) + th(thead1[3]) + th(thead1[4])
		for x in range(counts):
			tbody1 = ['timeout_'+str(x+1),tod[x].split('/')[-1], tod[x], "Timeout", "Details"]
			Tbody1 = Plan #<< tbody()
			Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(p(tbody1[3], cl="label label-danger")) + td(a(tbody1[4], href="/layout-test-results/fast/canvas/OffscreenCanvas-2d-drawImage.html"))
		# end

		# 测试计划 start
		tfd = self.dict['Text_Failuredata']
		counts = len(tfd)
		Text_Failure = Container << div(id="Text_Failure", cl="row")
		PlansTitle = Text_Failure << div(id="plans-title", cl="panel panel-primary") << div(cl="panel-heading") << span(plans_title, cl="text-uppercase")
		Plan = Text_Failure << div(id="Plan", cl="col-xs-12 col-md-12") << table(cl="table table-striped")
		Plan << p()
		Thead1 = Plan
		Thead1 << tr() << th(thead1[0]) + th(thead1[1]) + th(thead1[2]) + th(thead1[3]) + th(thead1[4])
		for x in range(counts):
			tbody1 = ['textfailure_'+str(x+1),tfd[x].split('/')[-1], tfd[x], "Text_Failure", "Details"]
			Tbody1 = Plan
			Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(p(tbody1[3], cl="label label-danger")) + td(a(tbody1[4], href="/layout-test-results/fast/canvas/OffscreenCanvas-2d-drawImage.html"))
		# end


		# 测试计划 start
		ifd = self.dict['Image_Filuredata']
		counts = len(ifd)
		Image_Filure = Container << div(id="Image_Filure", cl="row")
		PlansTitle = Image_Filure << div(id="plans-title", cl="panel panel-primary") << div(cl="panel-heading") << span(plans_title, cl="text-uppercase")
		Plan = Image_Filure << div(id="Plan", cl="col-xs-12 col-md-12") << table(cl="table table-striped")
		Plan << p()
		Thead1 = Plan
		Thead1 << tr() << th(thead1[0]) + th(thead1[1]) + th(thead1[2]) + th(thead1[3]) + th(thead1[4])
		for x in range(counts):
			tbody1 = ['imagefilure_'+str(x+1),ifd[x].split('/')[-1], ifd[x], "Image_Filure", "Details"]
			Tbody1 = Plan
			Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(p(tbody1[3], cl="label label-danger")) + td(a(tbody1[4], href="/layout-test-results/fast/canvas/OffscreenCanvas-2d-drawImage.html"))
		# end

		# 测试计划 start
		itfd = self.dict['Image_Test_Fiuredata']
		counts = len(itfd)
		Image_Test_Fiure = Container << div(id="Image_Test_Fiure", cl="row")
		PlansTitle = Image_Test_Fiure << div(id="plans-title", cl="panel panel-primary") << div(cl="panel-heading") << span(plans_title, cl="text-uppercase")
		Plan = Image_Test_Fiure << div(id="Plan", cl="col-xs-12 col-md-12") << table(cl="table table-striped")
		Plan << p()
		Thead1 = Plan
		Thead1 << tr() << th(thead1[0]) + th(thead1[1]) + th(thead1[2]) + th(thead1[3]) + th(thead1[4])
		for x in range(counts):
			tbody1 = ['image_and_testfiure_'+str(x+1),itfd[x].split('/')[-1], itfd[x], "Image_Test_Fiure", "Details"]
			Tbody1 = Plan #<< tbody()
			Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(p(tbody1[3], cl="label label-danger")) + td(a(tbody1[4], href="/layout-test-results/fast/canvas/OffscreenCanvas-2d-drawImage.html"))
		# end

		# 测试计划 start
		msd = self.dict['Missingdata']
		counts = len(msd)
		Missing = Container << div(id="Missing", cl="row")
		PlansTitle = Missing << div(id="plans-title", cl="panel panel-primary") << div(cl="panel-heading") << span(plans_title, cl="text-uppercase")
		Plan = Missing << div(id="Plan", cl="col-xs-12 col-md-12") << table(cl="table table-striped")
		Plan << p()
		Thead1 = Plan
		Thead1 << tr() << th(thead1[0]) + th(thead1[1]) + th(thead1[2]) + th(thead1[3]) + th(thead1[4])
		for x in range(counts):
			tbody1 = ['missing_'+str(x+1),msd[x].split('/')[-1], msd[x], "Missing", "Details"]
			Tbody1 = Plan
			Tbody1 << tr() << th(tbody1[0], scope="row") + td(tbody1[1]) + td(tbody1[2]) + td(p(tbody1[3], cl="label label-danger")) + td(a(tbody1[4], href="/layout-test-results/fast/canvas/OffscreenCanvas-2d-drawImage.html"))
		# end

		page.printOut('Pyh_Template.html')

if __name__ == '__main__':
	PH = PutHTML()
	PH.pyhport()
